//
//  AlipayManager.m
//  duzhoumo
//
//  Created by 度周末网络-王腾 on 16/3/10.
//  Copyright © 2016年 dzmmac. All rights reserved.
//

#import "AlipayManager.h"

@implementation AlipayManager
+(instancetype)sharedManager {
    static dispatch_once_t onceToken;
    static AlipayManager *instance;
    dispatch_once(&onceToken, ^{
        instance = [[AlipayManager alloc] init];
    });
    return instance;
}

#pragma mark -----------------支付宝支付回掉-----------------
- (void)alipay:(NSURL *)url application:(UIApplication *)application{
    if ([url.host isEqualToString:@"safepay"]) {
        [[AlipaySDK defaultService]
         processOrderWithPaymentResult:url
         standbyCallback:^(NSDictionary *resultDic) {
             if (resultDic){
                 if ([resultDic[@"resultStatus"] integerValue] == 9000){
                     if ([self.delegate respondsToSelector:@selector(alipayPayRespSuccess)]) {
                         [self.delegate alipayPayRespSuccess];
                     }
                 }
                 else{
                     //交易失败
                 }
             }
             else{
                 //失败
             }
         }];
    }
}

-(void)alipaySdk:(NSString *)order{
    NSString* orderInfo = [order  stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[AlipaySDK defaultService] payOrder:orderInfo fromScheme:@"busalipay" callback:^(NSDictionary *resultDic) {
        if (resultDic){
            if ([resultDic[@"resultStatus"] integerValue]== 9000){
                
                if ([self.delegate respondsToSelector:@selector(alipayPayRespSuccess)]) {
                    [self.delegate alipayPayRespSuccess];
                }
                
            }
            else{
                //交易失败
            }
        }else{
            //失败
        }
    }];
}

@end
